<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no" />
    <title>title</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css"/>
    <style>
        html, body {
            background-color: #f8f8f8;
        }
        .main {
        	background-color: #fff;
        }
        .main ul li .li_box {
        	height: 70px;
        	border-bottom: 1px solid #e8e8e8;
        	display: -webkit-box;
        	display: -webkit-flex;
        	align-items: center;
        	padding: 0 15px;
        }
        .main ul li:last-child .li_box {
        	border-bottom: none;
        }
        .main ul li .li_box .li_boxl {
        	width: 0;
        	flex: 1;
        	-webkit-flex: 1;
        	box-flex: 1;
        	-webkit-box-flex: 1;
        	padding-right: 10px;
        }
        .main ul li .li_box .income {
        	color: #333;
        	font-size: 15px;
            margin-bottom: 12px;
        }
        .main ul li .li_box .income span {
            font-size: 16px;
            color: #e62442;
        }
        .main ul li .li_box .li_boxl .time {
            font-size: 12px;
            color: #999;
        }
        .main ul li .li_box .li_boxr img {
        	height: 13px;
        	display: block;
        }
        .loading{
            color: #ccc;
            text-align: center;
            line-height: 25px;
            display: none;
        }
        .without_data{
            display: none;
            color:#ccc;
            text-align:center;
            padding-top: 75%;
            background: #f8f8f8;
        }
        .hidden_img {
            display: none;
        }
    </style>
</head>
<body>
    <div class="main">
        <div class="without_data">暂无记录</div>
    	<ul id="data_ul">
<!--     		<li tapmode onclick="fnGrantDetail();">
    			<div class="li_box">
    				<div class="li_boxl">
                        <div class="income">已结算收入： <span>RM 2435</span></div>            
                        <div class="time">发放时间： 2017-03-23 20:23:12</div>
                    </div>
    				<div class="li_boxr">
    					<img src="../image/right.png">
    				</div>
    			</div>
    		</li> -->

    	</ul>
        <div class="loading">loading...</div>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/zepto.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript" src="../script/doT.min.js"></script>
<script id="dataTpl" type="text/x-dot-template">
    {{ for(var i=0;i<it.length;i++){ }}
        <li tapmode onclick="fnGrantDetail({{=it[i]['id']}});">
            <div class="li_box">
                <div class="li_boxl">
                    <div class="income">已结算收入： <span>RM {{=it[i]['amount']}}</span></div>            
                    <div class="time">发放时间： {{=it[i]['create_time']}}</div>
                </div>
                <div class="li_boxr">
                    <img src="../image/right.png">
                </div>
            </div>
        </li>
    {{ }; }}
</script>
<script type="text/javascript">
    apiready = function(){
        shop = $api.getStorage('shop_data');
        p = 1;
        canLoad = true;
        //下拉刷新
        api.setCustomRefreshHeaderInfo({
            bgColor: '#f8f8f8',
            loadAnimInterval:60,
            image: {
               pull: pullArr,
               load: loadArr
            }
        }, function(ret, err) {
            p = 1;
            fnGetRecord(1);
        });

        //上拉加载
        api.addEventListener({
            name:'scrolltobottom',
            extra:{
                threshold:0            //设置距离底部多少距离时触发，默认值为0，数字类型
            }
        }, function(ret, err){
            if(canLoad) {
                p++;
                if($(window).scrollTop()) {
                    $(".loading").show();
                }
                fnGetRecord(2);
            }
        });

        fnGetRecord();
    };

    // 发放详情
    function fnGrantDetail(id) {
        api.openWin({
            name: 'grant_detail',
            url: './grant_detail.html',
            pageParam: {
                id:id
            }
        });
    }

    function fnGetRecord(type) {
        if(canLoad == false) {
            return;
        }
        canLoad = false;
        api.ajax({
            url: rootPath+'/api/seller/get_income_record',
            method: 'get',
            cache: true,
            data: {
                values: { 
                    shop_id : shop.id,
                    token:shop.token,
                    type:'shop',
                    p:p,
                    s_id:shop.id
                },
            }
        }, function(ret, err) {
            //type=1 下拉刷新，清除原来数据
            if(type == 1) {
                $('#data_ul').empty();
            }
            if (ret) {
                if(ret.status == 200) {
                    $('.without_data').hide();
                    appendDotData(ret.data,'dataTpl','data_ul',true);
                }else {
                    if(p == 1) {
                        $('.without_data').show();
                    }
                }
            } else {
                alert(JSON.stringify(err.msg))
            }
            if(type == 1) {
                // 是下拉刷新的，要收回
                api.refreshHeaderLoadDone();
            }
            if(type == 2) {
                //上拉给点假时间,好看些         
                setTimeout(function(){
                    $(".loading").hide();
                },1000);
                setTimeout(function(){
                    canLoad = true;
                },1100)
            }else {
                $('.loading').hide();
                canLoad = true;
            }
            closeLoading();
        });
    }
</script>
</html>